﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UtilZ.Dotnet.Ex.Log;
using UtilZ.Dotnet.WindowsDesktopEx.Winform;

namespace DotnetWinFormApp
{
    public partial class TestEllipseRotateLoadingControl : Form
    {
        public TestEllipseRotateLoadingControl()
        {
            InitializeComponent();
        }

        private void TestEllipseRotateLoadingControl_Load(object sender, EventArgs e)
        {
            if (this.DesignMode)
            {
                return;
            }

            var redirectAppenderToUI = (RedirectAppender)Loger.GetAppenderByName(null, "RedirectToUI");
            if (redirectAppenderToUI != null)
            {
                redirectAppenderToUI.RedirectOuput += RedirectLogOutput;
            }
        }

        private void RedirectLogOutput(object sender, RedirectOuputArgs e)
        {
            // logControl1.AddLog(e.Item.Content, e.Item.Level);

            //string str;
            //try
            //{
            //    str = string.Format("{0} {1}", DateTime.Now, e.Item.Content);
            //}
            //catch (Exception ex)
            //{
            //    str = ex.Message;
            //}

            //logControl.AddLog(str, e.Item.Level);
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //logControl1.Clear();
        }





        private EllipseRotateLoadingControl _control = null;
        private void btnTest_Click(object sender, EventArgs e)
        {
            if (this._control != null)
            {
                return;
            }

            var control = new EllipseRotateLoadingControl();
            control.BackColor = Color.Gray;
            control.FillBrushes = new Brush[] { Brushes.Red, Brushes.Black, Brushes.Blue, Brushes.Yellow };
            //control.EllipseSize = 10;
            //control.Size = new Size(30, 30);
            control.EllipseSize = 10f;
            control.Size = new Size(54, 54);



            //control.Interval = 40;
            control.DurationMilliseconds = 1200;
            control.RotateDirection = true;

            //control.Interval = 30;
            //control.AngleStep = 12;

            //control.FillBrushes = new Brush[]
            //{
            //    Brushes.Green,
            //    Brushes.Blue,
            //    Brushes.Yellow,
            //    Brushes.Red,
            //    Brushes.Black,
            //    Brushes.Gray,
            //    Brushes.Gray,
            //    Brushes.Gray,
            //};
            control.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            control.Location = new Point(20, 30);
            //panel2.Controls.Add(control);

            panel1.Controls.Add(control);
            panel1.Controls.SetChildIndex(control, 0);

            //opacityPanel1.Controls.Add(control);
            //opacityPanel1.Controls.SetChildIndex(control, 0);

            this._control = control;

        }


        private void btnStartAnimal_Click(object sender, EventArgs e)
        {
            if (this._control != null)
            {
                this._control.StartAnimal();
            }

            //ellipseRotateLoadingControl1.StartAnimal();
        }



        private void btnStopAnimal_Click(object sender, EventArgs e)
        {
            if (this._control != null)
            {
                this._control.StopAnimal();
            }

            //ellipseRotateLoadingControl1.StopAnimal();
        }

        private void btnClearRegion_Click(object sender, EventArgs e)
        {
            if (this._control != null)
            {
                //this._control.Clear();
            }
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            if (this._control != null)
            {
                //ellipseRotateLoadingControl1.EllipseSize = trackBar1.Value;
                _control.EllipseSize = trackBar1.Value;
            }
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            if (this._control != null)
            {
                //ellipseRotateLoadingControl1.Interval = trackBar2.Value;
                _control.Interval = trackBar2.Value / 10;
                label1.Text = _control.Interval.ToString();
            }
        }
    }
}
